package com.haois.mp.wechat.handler;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 消息默认处理器
 *
 */
@Component
public class DefaultHandler extends AbstractHandler implements WxMpMessageHandler {

	@Override
	public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
		String content = this.execute(wxMpXmlMessage,wxMpService);
		return WxMpXmlOutMessage.TEXT()
				.fromUser(wxMpXmlMessage.getToUser())
				.toUser(wxMpXmlMessage.getFromUser())
				.content(content).build();
	}
	@Override
	public String execute(WxMpXmlMessage wxMpXmlMessage,WxMpService wxMpService) {
		String content = "欢迎使用 MobileGroup 微信端，更多功能敬请期待。";
		return content;
	}
}
